var longitude = 0;
var latitude = 0;
var province=0;

$(function() {
	// 加载loadding
	//showLoadding();
	$("body").append("<script src=\"http://api.map.baidu.com/api?v=2.0&ak=nrCmUgvjHhmWNdnLOe4Uvgc1v8hWX9kQ&callback=initialize\"></script>");
	
});

function initialize() {
	if (navigator.geolocation) {
		var geolocation = new BMap.Geolocation();
		geolocation.getCurrentPosition(function(r) {
			if (this.getStatus() == BMAP_STATUS_SUCCESS) {
				longitude = r.longitude;
				latitude = r.latitude;
				var centerPoint = new BMap.Point(r.longitude, r.latitude);
				var gc = new BMap.Geocoder();
				gc.getLocation(centerPoint, function(rs) {
					var addComp = rs.addressComponents;
				province = addComp.province;
				
				showLoadding();
				//根据省份查询奖券
				$.ajax({
					headers:{'Cookie':document.cookie},
//					url:"http://127.0.0.1:9013/pointActivity/api/v1/findByIalize",
					url:rootPath + "/pointActivity/api/v1/findByIalize",
					data:"province="+province,
					type:"POST",
					success:function(json){
						hideLoadding();
						for(var a in json){
							var sum=json[a];
							var arr=new Array();
							arr=(sum+'').split('');
							if(arr.length=="4"){
								for(var i=arr.length-1;i>=0;i--){
									var s=arr[i];
									$("#img"+i+"").attr("src","images/"+s+".png");
								}
							}
							if(arr.length=="3"){
								for(var i=arr.length-1;i>=0;i--){
									var s=arr[i];
									var id=i+1;
									$("#img"+id+"").attr("src","images/"+s+".png");
								}
							}
							if(arr.length=="2"){
								for(var i=arr.length-1;i>=0;i--){
									var s=arr[i];
									var id=i+2;
									$("#img"+id+"").attr("src","images/"+s+".png");
								}
							}
							if(arr.length=="1"){
								for(var i=arr.length-1;i>=0;i--){
									var s=arr[i];
									var id=i+3;
									$("#img"+id+"").attr("src","images/"+s+".png");
								}
							}
						}
					}
				 });
			 });
			} else {
				alert('failed' + this.getStatus());
			}
		}, {enableHighAccuracy : true});
	} else {
		map.addControl(new BMap.GeolocationControl());
	}
	// 关闭loading
	//hideLoadding();
}




